
//数据
const mockStores = []


mockStores.forEach(store => {
  //年营业额
  // const sum = store.dailyData.reduce((acc, day) => {
  //   return acc + (day.revenue?.amount || 0)
  // }, 0)
  // store.annualData.yearAmount = sum

  //月营业额
  // 初始化按月营业额汇总对象
  const monthlyRevenue = {};
  // 计算各月营业额总和
  store.dailyData.forEach(day => {
    const month = parseInt(day.date.split('-')[1], 10); // 提取月份数字
    monthlyRevenue[month] = (monthlyRevenue[month] || 0) + day.revenue.amount;
  });
  // 将月营业额添加到monthlyData
  store.monthlyData.forEach(monthData => {
    monthData.totalRevenue = monthlyRevenue[monthData.month] || 0;
  });
  // 年营业额计算
  const annualSum = store.monthlyData.reduce((sum, m) => sum + m.totalRevenue, 0);
  store.annualData.yearAmount = annualSum
})


const fs = require('fs');
fs.writeFileSync('newStores.json',
  JSON.stringify(mockStores, null, 2));